package com.wanxi.servlet;

import com.alibaba.fastjson2.JSONObject;
import com.wanxi.dto.ProductDetailDTO;
import com.wanxi.dto.ResultDTO;
import com.wanxi.model.CompanyModel;
import com.wanxi.model.CuisineModel;
import com.wanxi.service.CompanyService;
import com.wanxi.service.CuisineService;
import com.wanxi.service.ProductService;
import com.wanxi.service.impl.CompanyServiceImpl;
import com.wanxi.service.impl.CuisineServiceImpl;
import com.wanxi.service.impl.ProductServiceImpl;
import com.wanxi.util.Tool;
import com.wanxi.vo.ProductVO;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/detail")
public class ProductDetailServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //        1。乱码处理
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
//        2.得到前端的值


//        3.封装到VO

//        4.调用服务逻辑层
        CompanyService companyService = new CompanyServiceImpl();
        CuisineService cuisineService = new CuisineServiceImpl();
//        5.得到逻辑层的返回结果
        CompanyModel companyModel = companyService.getCompanyModel();
        List<CuisineModel> cuisineModelList = cuisineService.getCuisineModelList();
        ProductDetailDTO productDetailDTO=new ProductDetailDTO();
        productDetailDTO.setCompanyModel(companyModel);
        productDetailDTO.setCuisineModelList(cuisineModelList);
//        6.将结果返回给前端
        resp.getWriter().println(JSONObject.toJSONString(productDetailDTO));

    }
}
